-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for scoped registry urls #4
Conversation
see https://docs.npmjs.com/misc/scope#associating-a-scope-with-a-registry using node module rc to get the config (global and project specific) and use the registry url of the scope if existing, fallback to the official registry.npmjs.org
Hi! Thank you for the pull request and detailed explanation of how it works! Overall the approach of using of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall great, please check the comments;
If possible run it through eslint
, it has a config.
Thank you!
lib/getPackageDetails.js
Outdated
@@ -70,6 +72,11 @@ module.exports = function getPackageDetails( | |||
return Promise.resolve(null); | |||
} | |||
const key = `${name}@${versionLoose}`; | |||
const scope = (/(@[^\/]+)\/.*/.test(name) && /(@[^\/]+)\/.*/.exec(name)[1]) || ``; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to use https://github.com/npm/npm-package-arg (because npm
uses it)
or alternatively copy logic from it to be on safe side 😉
this.scope = name[0] === '@' ? name.slice(0, name.indexOf('/')) : undefined
// scoped packages in couch must have slash url-encoded, e.g. @foo%2Fbar
this.escapedName = name.replace('/', '%2f')
It's difficult to say if your regexp works exactly. the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just changed the parsing to the same logic, thanks for the hint
lib/getPackageDetails.js
Outdated
var registryUrl = (scope && npmConfig[`${scope}:registry`]) || npmConfig[`registry`]; | ||
if(registryUrl.charAt(registryUrl.length - 1) !== `/`) { | ||
registryUrl += `/`; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/getPackageDetails.js
Outdated
@@ -70,6 +72,11 @@ module.exports = function getPackageDetails( | |||
return Promise.resolve(null); | |||
} | |||
const key = `${name}@${versionLoose}`; | |||
const scope = (/(@[^\/]+)\/.*/.test(name) && /(@[^\/]+)\/.*/.exec(name)[1]) || ``; | |||
var registryUrl = (scope && npmConfig[`${scope}:registry`]) || npmConfig[`registry`]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let
please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed together with the remaining eslint errors
Thank you @killerfurbel ! |
Published as |
I got across this when checking one of my projects which contains modules from SAP (@sap/ prefix), those modules are hosted on npm.sap.com. To be able to
npm install
those modules, you need to add this setting to the npm config (for example, to the user config):@sap:registry = "https://npm.sap.com"
see https://docs.npmjs.com/misc/scope#associating-a-scope-with-a-registry
I was looking for a way to get these npm settings and came across npm-conf, but this module mainly relied on a dependency config-chain to get the configuration. I checked this one and it said:
So I went with rc, which does the job.
rc has the following dependencies:
Now rc is used to get the config (global and project specific), the module key is checked for a scope using a regex (starting with @, containing a /). If there is a scope, try to use the registry url of the scope, fallback to the official registry.npmjs.org
npm config is fine when the scoped registry URL does not end with a /, but since we just concaternate the module name, we need to add a / to the url if it doesn't end with one...